#ifndef TIMER_H_INCLUDED
#define TIMER_H_INCLUDED

#include "StopWatch.h"
#include <my/Config.h>

namespace my {

/**
* @class Timer
* @brief Create a Timer. A Timer is a watch that starts at a given time and that decrease to reach zero.
* @code
my::Timer timer(5.f); // Create a timer of 5.0 seconds
timer.start(); // Start the timer
while(!timer.isExpired())
{
    // While the timer is not expired
    // Do something...
}
* @endcode
*/
class MYAPI Timer
{
    public:
        /**
        * @brief Default Constructor. To use the Timer you will need to use reset(float timeLimit, bool continueRunning).
        */
        Timer();

        /**
        * @brief Recommended constructor.
        * @param timeLimit The starting time of the Timer. It will decrease to zero.
        * @param initRunning Set it true if you want to start the timer at construction
        */
        Timer(float timeLimit, bool initRunning = false);

        /**
        * @brief Default destructor.
        */
        virtual ~Timer();

        /**
        * @brief Return the time remaining to reach zero, or zero if the reamining timer is over
        * @return The remaining time, in seconds, or zero if timer is expired
        */
        float   getRemainingTime()      const;

        /**
        * @brief Return if the Timer is running or not
        * @return true if running, else false
        */
        bool    isRunning()             const;

        /**
        * @brief Return if the Timer is expired or not
        * @return true if expired, else false
        */
        bool    isExpired()             const;

        /**
        * @brief To start the Timer
        */
        void    start();

        /**
        * @brief To stop the Timer
        */
        void    stop();

        /**
        * @brief To reset the Timer
        * @param timeLimit The starting time of the Timer. It will decrease to zero.
        * @param continueRunning Set it true if you want to restart the timer
        */
        void    reset(float timeLimit, bool continueRunning = false);

        /**
        * @brief To reset the Timer, the old time limit will be kept
        * @param continueRunning Set it true if you want to restart the timer
        */
        void    reset(bool continueRunning = false);

    private:
        StopWatch   _clock;
        float       _timeLimit;
};

} // namespace

#endif // TIMER_H_INCLUDED
